package ysf.com.mediumdifficulty;

import java.util.*;

/**
 * @author ysf
 * @date 2021/6/30 22:02
 */
public class FifteenthDemos {

    public static void main(String[] args) {
        int[] nums= new int[]{-1,0,1,2,-1,4};
        Set<List<Integer>> lists = threeSum(nums);

        System.out.println(lists);
    }

    public static Set<List<Integer>> threeSum(int[] nums){

        Set<List<Integer>> res = new HashSet<List<Integer>>();
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            for (int j = i+1; j < nums.length; j++) {
                for (int k = j+1; k < nums.length; k++) {
                    if(nums[i] + nums[j] +nums[k] == 0){
                        List<Integer> temp = new ArrayList<>();
                        temp.add(nums[i]);
                        temp.add(nums[j]);
                        temp.add(nums[k]);
                        Collections.sort(temp);
                        res.add(temp);
                    }
                }
            }
        }
        return res;
    }











}
